package com.andy.nature.ui.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import com.andy.nature.BR
import com.andy.nature.R
import com.andy.nature.databinding.DialogBottomItemBinding
import com.andy.nature.model.TestBean

class DialogBottomAdapter : RecyclerView.Adapter<DialogBottomAdapter.BottomViewHolder>() {

    private var mContext: Context? = null
    private var mList = ArrayList<TestBean>()

    override fun onAttachedToRecyclerView(recyclerView: RecyclerView) {
        super.onAttachedToRecyclerView(recyclerView)
        mContext = recyclerView.context
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BottomViewHolder {
        val view = LayoutInflater.from(mContext).inflate(R.layout.dialog_bottom_item, parent, false)
        return BottomViewHolder(view)
    }

    override fun onBindViewHolder(holder: BottomViewHolder, position: Int) {
        val bind = DataBindingUtil.bind<DialogBottomItemBinding>(holder.itemView)
        bind?.setVariable(BR.dialog, mList[position])
        bind?.executePendingBindings()
    }

    override fun getItemCount(): Int {
        return mList.size
    }

    fun setList(list: ArrayList<TestBean>) {
        mList = list
        notifyDataSetChanged()
    }

    class BottomViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {}


}